home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / PowerPlant / Temperature / CTemperatureDoc.cp < prev    next >
Encoding:
Text File  |  1998-10-11  |  5.4 KB  |  242 lines  |  [TEXT/CWIE]

  1. // CTemperatureDoc.cp -- Document methods
  2.  
  3. #include "CTemperatureDoc.h"
  4. #include "CTemperatureData.h"
  5.  
  6. #include "DDocData.h"
  7. #include "CMainWindow.h"
  8. #include "TemperatureCmds.h"
  9.  
  10. #include <LFile.h>
  11. #include <LPlaceHolder.h>
  12. #include <LPrintout.h>
  13. #include <LString.h>
  14. #include <LWindow.h>
  15. #include <TArrayIterator.h>
  16. #include <UWindows.h>
  17.  
  18. const ResIDT    prto_PrintView        = 201;
  19. const ResIDT    STRx_Untitled        = 128;
  20.  
  21. // ---------------------------------------------------------------------------
  22. //        • CTemperatureDoc
  23. // ---------------------------------------------------------------------------
  24.  
  25. CTemperatureDoc::CTemperatureDoc(
  26.     LCommander    *inSuper)
  27.     : LSingleDoc(inSuper)
  28. {
  29.     mData = new CTemperatureData();
  30. }
  31.  
  32. // ---------------------------------------------------------------------------
  33. //        • ~CTemperatureDoc
  34. // ---------------------------------------------------------------------------
  35. //    Destructor
  36. //
  37.  
  38. CTemperatureDoc::~CTemperatureDoc()
  39. {
  40.     // Delete all SubCommanders - copied from LCommander
  41.     // This fixes a bug that existed in CW11 and prior.
  42.     // It appears that the bug is fixed in CW Pro 1,
  43.     // so this code probably is no longer needed.
  44.     TArrayIterator<LCommander*> iterator(mSubCommanders, LArrayIterator::from_End);
  45.     LCommander*        theSub;
  46.     while (iterator.Previous (theSub)) {
  47.         mSubCommanders.RemoveItemsAt (1, iterator.GetCurrentIndex());
  48.         delete theSub;
  49.     }
  50.     mWindow = nil;
  51.  
  52.     delete mData;
  53. }
  54.  
  55. //----------
  56. void
  57. CTemperatureDoc::newFile()
  58. {
  59.     mData->NewData();
  60.  
  61.     MakeWindows();
  62.  
  63.     NameNewDoc();        // Set name of untitled window
  64. }
  65.  
  66. //----------
  67. void
  68. CTemperatureDoc::openFile(
  69.     FSSpec        *inFileSpec)
  70. {
  71.     mData->OpenData (inFileSpec);
  72.  
  73.     MakeWindows();
  74.  
  75.     if (mWindow != nil) {
  76.         mWindow->SetDescriptor (inFileSpec->name);
  77.     }
  78.     mIsSpecified = true;
  79. }
  80.  
  81. // ---------------------------------------------------------------------------
  82. //        • MakeWindows
  83. // ---------------------------------------------------------------------------
  84.  
  85. void
  86. CTemperatureDoc::MakeWindows()
  87. {
  88.     DDocData*        docData = mData->GetDocData ();
  89.  
  90.     mMainWindow = CMainWindow::CreateMainWindow(this, docData);
  91.  
  92.     mWindow = mMainWindow;
  93. }
  94.  
  95. // ---------------------------------------------------------------------------
  96. //        • NameNewDoc
  97. // ---------------------------------------------------------------------------
  98. //    Name a new, untitled document window
  99. //
  100. //    Untitled windows start with "untitled", then "untitled 1",
  101. //    "untitled 2", etc. Old numbers are reused, so there won't be
  102. //    gaps in the numbering.
  103. //
  104. //    This routine uses a STR# resource to store the "untitled" string,
  105. //    which can be localized to different languages. The first string
  106. //    is "untitled" and the second is "untitled " (trailing space),
  107. //    which is used when appending a number to the name.
  108.  
  109. void
  110. CTemperatureDoc::NameNewDoc()
  111. {
  112.     // Start with the default name("untitled")
  113.     Str255    name;
  114.     ::GetIndString(name, STRx_Untitled, 1);
  115.  
  116.     long    num = 0;
  117.     while (UWindows::FindNamedWindow(name) != nil) {
  118.  
  119.             // An existing window has the current name
  120.             // Increment counter and try again
  121.  
  122.         ::GetIndString(name, STRx_Untitled, 2);
  123.         num++;
  124.         Str15    numStr;
  125.         ::NumToString(num, numStr);
  126.         LString::AppendPStr(name, numStr);
  127.     }
  128.  
  129.     mWindow->SetDescriptor(name);        // Finally, set window title
  130. }
  131. // ---------------------------------------------------------------------------
  132. //        • IsModified
  133. // ---------------------------------------------------------------------------
  134. //    Return whether the Document has changed since the last save
  135.  
  136. Boolean
  137. CTemperatureDoc::IsModified()
  138. {
  139.     mIsModified = mData->IsDirty();
  140.  
  141.     return mIsModified;
  142. }
  143.  
  144. // ---------------------------------------------------------------------------
  145. //        • DoAESave
  146. // ---------------------------------------------------------------------------
  147. //    Save Document in the specified file with the specified file type
  148. //
  149. //    If file type is fileType_Default, use the normal file type for
  150. //    this document
  151.  
  152. void
  153. CTemperatureDoc::DoAESave(
  154.     FSSpec    &inFileSpec,
  155.     OSType    inFileType)
  156. {
  157.     mData->DoSaveAs(&inFileSpec);                // Write out data
  158.                                         // Change window name
  159.     mWindow->SetDescriptor(inFileSpec.name);
  160. }
  161.  
  162. //----------
  163. void
  164. CTemperatureDoc::DoSave()
  165. {
  166.     mData->DoSave();
  167. }
  168.  
  169. //----------
  170. void
  171. CTemperatureDoc::DoRevert()
  172. {
  173.     mData->DoRevert();
  174. }
  175.  
  176. // ---------------------------------------------------------------------------
  177. //        • DoPrint
  178. // ---------------------------------------------------------------------------
  179. //    Print the contents of the Document
  180.  
  181. void
  182. CTemperatureDoc::DoPrint()
  183. {
  184.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  185.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  186.                                     thePrintout->FindPaneByID('TBox');
  187. //!    textPlace->InstallOccupant(mTextView, atNone);
  188.  
  189.  
  190.     thePrintout->DoPrintJob();
  191.     delete thePrintout;
  192. }
  193.  
  194. //----------
  195. Boolean
  196. CTemperatureDoc::ObeyCommand(
  197.     CommandT    inCommand,
  198.     void*        ioParam)
  199. {
  200.     Boolean        cmdHandled = true;
  201.  
  202.     if (inCommand < 0) {
  203.         // modal dialog has finished
  204.  
  205.         switch (-inCommand) {
  206.         }
  207.  
  208.     } else {
  209.         switch (inCommand) {
  210.  
  211.         default:
  212.                 cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  213.             break;
  214.         }
  215.     }
  216.  
  217.     return cmdHandled;
  218. }
  219.  
  220. //----------
  221. void
  222. CTemperatureDoc::FindCommandStatus(
  223.     CommandT    inCommand,
  224.     Boolean        &outEnabled,
  225.     Boolean        &outUsesMark,
  226.     Char16        &outMark,
  227.     Str255        outName)
  228. {
  229.     outUsesMark = false;
  230.  
  231.     switch (inCommand) {
  232.  
  233.     // +++ Add cases here for the commands you handle
  234.  
  235.  
  236.     default:
  237.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  238.                                             outUsesMark, outMark, outName);
  239.         break;
  240.     }
  241. }
  242.